<?php
$mysqli=new mysqli('localhost','root','','test');

if ($mysqli->connect_error)// 检测连接
{
    die("连接失败" . $mysqli->connect_error);
} 

$mysqli->set_charset('utf8');//设置默认的客户端编码方式

$username=$_POST["user"];
$password=strrev($_POST["password"]);//密码字符串反向加密

class User//创建类user
{
	private $username;//成员
	private $password;//成员
	function __construct($u,$p)//初始化对象
	{
		$this-> username = $u;
		$this-> password = $p;
	}
	function authentication()//登录验证
	{
		$mysqli=new mysqli('localhost','root','','test');
		$newUsername=json_encode($this-> username);
		$newPassword=json_encode($this-> password);
		$sql = "SELECT * FROM user WHERE `username`=$newUsername AND `password`=$newPassword";
		$result = $mysqli->query($sql);
		$num  =  $result->num_rows;
		if ($num>0)
		{
			echo "登录成功,欢迎 $this->username<br>";
		}
		else
		{
			header('refresh:3; url=login.php');
			echo "用户名或密码输入错误,将在3秒后跳转到登录界面！";
	 		exit;
		}
	}
	function display()//显示用户信息
	{
		echo "<br>用户信息<br>";
		echo "账号：".$this-> username."<br>";
	}
}
$stu = new User("$username","$password");
$stu->authentication();
$stu->display();
?>